package com.hangup.activity;


import com.devil.bbsclient.R;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
		tabHost.setup();/* 必不可少、组件内部用来找到TabWidget和FrameLayout */

		Intent intent = new Intent().setClass(this, BBSActivity.class);
		setupTab(tabHost, "论坛", R.drawable.tab_item_bbs, intent);

		intent = new Intent().setClass(this, SchoolActivity.class);
		setupTab(tabHost, "校园资讯", R.drawable.tab_item_school, intent);

		intent = new Intent().setClass(this, WeatherActivity.class);
		setupTab(tabHost, "天气预报", R.drawable.tab_item_weather, intent);

		intent = new Intent().setClass(this, MoreActivity.class);
		setupTab(tabHost, "更多", R.drawable.tab_item_more, intent);
	}

	private void setupTab(TabHost tabhost, String tag, int drawable,
			Intent intent) {
		View tabview = createTabView(tabhost.getContext(), tag, drawable);
		TabSpec setContent = tabhost.newTabSpec(tag).setIndicator(tabview)
				.setContent(intent);
		tabhost.addTab(setContent);
	}

	private View createTabView(Context context, String text, int drawable) {
		View view = LayoutInflater.from(context).inflate(R.layout.tab, null);
		TextView tv = (TextView) view.findViewById(R.id.tabtext);
		tv.setText(text);
		ImageView iv = (ImageView) view.findViewById(R.id.tabicon);
		iv.setImageResource(drawable);
		return view;
	}

}
